import { create } from 'zustand';
import { persist } from 'zustand/middleware';

interface UserState {
  userId: number;
  token: string;
  userName: string;
  isAdmin: boolean;
  nickName: string;
  avatarUrl: string;
  setUserInfo: (userId: number, token: string, userName: string, isAdmin: boolean, nickName: string, avatarUrl: string) => void;
  clearUserInfo: () => void;
}

export const useUserStore = create<UserState>()(
  persist(
    (set) => ({
      userId: 0,
      token: '',
      userName: '',
      isAdmin: false,
      nickName: '',
      avatarUrl: '',
      setUserInfo: (userId: number, token: string, userName: string, isAdmin: boolean, nickName: string, avatarUrl: string) => 
        set(() => ({ userId, token, userName, isAdmin, nickName, avatarUrl })),
      clearUserInfo: () => 
        set(() => ({ userId: 0, token: '', userName: '', isAdmin: false, nickName: '', avatarUrl: '' })),
    }),
    {
      name: 'user-storage',
    }
  )
); 